
const app =  getApp()
Component({
    properties: {},
    data: {
        cart:{
            num: 0,
        },
    },
    lifetimes:{
        attached() {
            this.setData({
                ['cart.num']: app.globalData.cartNum
            })

            // 监听购物车变化
            app.watch('cartNum', (name, value) => {
                console.log("购物车数据变化", name)
                if (name == 'cartNum') {
                    this.setData({
                        [`cart.num`]: app.globalData.cartNum
                    });
                }
            })
        }
    },
    methods: {
        btnClick(e){
            const {type} = e.currentTarget.dataset

            if (type == 'goIndex'){
                wx.reLaunch({
                    url:"/pages/index/index"
                })
            }else if(type == 'goCart'){
                wx.reLaunch({
                    url:"/pages/user/cart"
                })
            }else{
                this.triggerEvent("click", {
                    type,
                })
            }

        },
    },
});
